import { ref } from 'vue'
import { useRoute } from 'vue-router'

export default function dataForm() {
  const route = useRoute()
  // 保存当前选中的算法类型
  const algorithmType = ref('')
  // 保存当前选中的问题类型
  const problemType = ref('')
  const baseForm = [
    { label: 'pop_size', name: 'pop_size', type: 'number', step: 1 },
    { label: 'obj_dim', name: 'obj_dim', type: 'number', step: 1 },
    { label: 'var_dim', name: 'var_dim', type: 'number', step: 1 },
    { label: 'maxFE', name: 'max_fun_eval', type: 'number', step: 1 }

  ]
  const MultipleForm = baseForm.concat([
    { label: 'run_size', name: 'run_size', type: 'number', step: 1 },
    { label: 'save_size', name: 'save_size', type: 'number', step: 1 }
  ])

  const formFields = ref(baseForm)
  const formOjb = { simpleCharts: baseForm, multipleTables: MultipleForm }
  // 监听路由变化
  watch(
    () => route.name,
    (newVal) => {
      formFields.value = formOjb[newVal]
    },
    { immediate: true }
  )
  return {
    formFields,
    algorithmType,
    problemType
  }
}
